#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
struct Student {
	string id;
	int de;
	int cai;
	int total;
};
vector<Student> S1,S2,S3,S4;

bool Cmp(const Student &x,const Student &y){
	if(x.total>y.total)return true;
	else if(x.total<y.total) return false;
	else{
		if(x.de>y.de) return true;
		else if(x.de<y.de) return false;
		else{
			int res=x.id.compare(y.id);
			return res<0;
		}
	}
}
void print_inf(vector<Student> S){
	for(auto s:S){
		cout<<s.id<<" "<<s.de<<" "<<s.cai<<endl;
	}
}
int main(){

	freopen("input.txt","r",stdin);
	int n,l,h;
	cin>>n>>l>>h;
	int k=0;
	while(n--){
		string id;
		int de,cai;
		cin>>id>>de>>cai;
		Student S;
		S.id=id;S.de=de;S.cai=cai;S.total=de+cai;
		if(de>=l&&cai>=l){
			k++;
			if(de>=h&&cai>=h){
				S1.push_back(S);
			}else if(cai<h&&de>=h&&cai<h){
				S2.push_back(S);
			}else if(cai<h&&de<h&&de>=cai){
				S3.push_back(S);
			}else{
				S4.push_back(S);
			}
		}
	}
	sort(S1.begin(),S1.end(),Cmp);
	sort(S2.begin(),S2.end(),Cmp);
	sort(S3.begin(),S3.end(),Cmp);
	sort(S4.begin(),S4.end(),Cmp);
	cout<<k<<endl;
	print_inf(S1);
	print_inf(S2);
	print_inf(S3);
	print_inf(S4);

	return 0;
}